package com.mine.yyb.modules.sys.controller;

import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mine.yyb.common.utils.exception.MineErrorCode;
import com.mine.yyb.common.utils.exception.MineException;
import com.mine.yyb.common.utils.execl.MineExcelReport;
import com.mine.yyb.common.utils.jdbc.MinePagination;
import com.mine.yyb.common.utils.json.MineJacksonkMapper;
import com.mine.yyb.common.web.YybBaseController;
import com.mine.yyb.modules.sys.bo.OrderBO;
import com.mine.yyb.modules.sys.enums.ShopSiteEnum;
import com.mine.yyb.modules.sys.enums.SysCodeEnum;
import com.mine.yyb.modules.sys.service.IOrderService;
import com.mine.yyb.modules.sys.vo.OrderVO;
import com.mine.yyb.modules.sys.vo.RyReportVO;

/**
 * <pre>
 * <一句话功能简述>
 * 
 * 订单相关control类
 * 
 * <功能详细描述>
 * </pre>
 * 
 * @author xuganhua
 * @version [版本号, 2015年12月29日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Controller
@RequestMapping(value = "/sys/order")
public class OrderControl extends YybBaseController
{
    @Autowired
    private IOrderService iOrderService;
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入系统订单页面
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月21日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initOrderPage")
    public String initOrderPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/order";
    }
    
    @RequestMapping(value = "/initQtOrderPage")
    public String initQtOrderPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/qtorder";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入日本亚马逊订单转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initJpamzConvertPage")
    public String initJpamzConvertPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/jpamz/convert";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入日本亚马逊商品链接转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initJpamzRecordPage")
    public String initJpamzRecordPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/jpamz/record";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入日本乐天商品链接转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initJpltConvertPage")
    public String initJpltConvertPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/jplt/convert";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入日本乐天商品登记页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initJpltRecordPage")
    public String initJpltRecordPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/jplt/record";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入lpm商品链接转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initLpmConvertPage")
    public String initLpmConvertPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/lpm/convert";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入lpm商品链接转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initLpmRecordPage")
    public String initLpmRecordPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/lpm/record";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入乐天国际商品链接转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initLtgjConvertPage")
    public String initLtgjConvertPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/ltgj/convert";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入乐天国际订单登记页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initLtgjRecordPage")
    public String initLtgjRecordPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/ltgj/record";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入中国海外购商品链接转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2018年03月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initCnhwgConvertPage")
    public String initCnhwgConvertPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/cnhwg/convert";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入中国海外购订单登记页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2018年03月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initCnhwgRecordPage")
    public String initCnhwgRecordPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/cnhwg/record";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入中国亚马逊商品链接转换页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initCnamzConvertPage")
    public String initCnamzConvertPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/cnamz/convert";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 进入中国亚马逊订单登记页
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年5月24日]
     * @param request
     * @param response
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/initCnamzRecordPage")
    public String initCnamzRecordPage(HttpServletRequest request, HttpServletResponse response)
    {
        getResponseHeader(response);
        return "/html/cnamz/record";
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 保存订单信息
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2015年12月29日]
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/saveOrder")
    public ResponseEntity<String> saveOrder(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        try
        {
            logger.info(orderBO.toString());
            
            // 验证innerID
            if (StringUtils.isBlank(orderBO.getInnerID()))
            {
                throw new MineException(SysCodeEnum.ERROR_INNERID_BLANK);
            }
            
            // 订单编号为空
            if (StringUtils.isBlank(orderBO.getOrderID()))
            {
                throw new MineException(SysCodeEnum.ERROR_ORDERID_BLANK);
            }
            
            // 订单价格小于0
            if (orderBO.getOrderPrice() < 0)
            {
                throw new MineException(SysCodeEnum.ERROR_ORDER_PRICE_BLANK);
            }
            
            if (StringUtils.isBlank(orderBO.getOrderDate()))
            {
                Date date = new Date();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd mm:hh:ss");
                orderBO.setOrderDate(simpleDateFormat.format(date));
            }
            
            retCode = iOrderService.saveOrder(orderBO);
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode);
    }
    
    /**
     * <一句话功能简述>
     *
     * 更新订单信息
     *
     * <功能详细描述>
     * 
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/updateOrder")
    public ResponseEntity<String> updateOrder(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        try
        {
            logger.info(orderBO.toString());
            
            // 订单编号为空
            if (StringUtils.isBlank(orderBO.getOrderID()))
            {
                throw new MineException(SysCodeEnum.ERROR_ORDERID_BLANK);
            }
            
            // 订单价格小于0
            if (orderBO.getOrderPrice() < 0)
            {
                throw new MineException(SysCodeEnum.ERROR_ORDER_PRICE_BLANK);
            }
            
            // 返利金额小于0
            if (orderBO.getRebate() < 0)
            {
                throw new MineException(SysCodeEnum.ERROR_ORDER_REBATE_BLANK);
            }
            
            // 分成金额小于0
            if (orderBO.getParentRebate() < 0)
            {
                throw new MineException(SysCodeEnum.ERROR_ORDER_PARENT_REBATE_BLANK);
            }
            
            retCode = iOrderService.updateOrder(orderBO);
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode);
    }
    
    /**
     * <一句话功能简述>
     * 
     * 更新所有的订单信息
     *
     * <功能详细描述>
     * 
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/updateAllOrder")
    public ResponseEntity<String> updateAllOrder(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        try
        {
            logger.info(orderBO.toString());
            
            // 订单编号为空
            if (StringUtils.isBlank(orderBO.getOrderID()))
            {
                throw new MineException(SysCodeEnum.ERROR_ORDERID_BLANK);
            }
            String[] orderIDs = orderBO.getOrderID().split(",");
            for (int i = 0; i < orderIDs.length; i++)
            {
                orderBO.setOrderID(orderIDs[i]);
                iOrderService.updateOrder(orderBO);
            }
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 更新订单信息
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年2月17日]
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/updateAllOrderTo")
    public ResponseEntity<String> updateAllOrderTo(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        try
        {
            logger.info(orderBO.toString());
            
            // 内部ID为空
            if (StringUtils.isBlank(orderBO.getInnerID()))
            {
                throw new MineException(SysCodeEnum.ERROR_INNERID_BLANK);
            }
            
            // 订单日期为空
            if (StringUtils.isBlank(orderBO.getOrderDate()))
            {
                throw new MineException(SysCodeEnum.ERROR_ORDERDATE_BLANK);
            }
            
            retCode = iOrderService.updateOrder(orderBO);
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 校验订单号是否已经存在
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2015年12月29日]
     * @param request
     * @param orderBO
     * @return
     * @throws MineException
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/checkOrder")
    public ResponseEntity<String> checkOrderExist(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
        throws MineException
    {
        boolean result = true;// 表示用户名已经存在
        Map<String, Boolean> map = new HashMap<String, Boolean>();
        map.put("valid", result);
        try
        {
            logger.info(orderBO.toString());
            
            // 订单编号为空
            if (StringUtils.isBlank(orderBO.getOrderID()))
            {
                throw new MineException(SysCodeEnum.ERROR_ORDERID_BLANK);
            }
            
            result = iOrderService.isOrderExist(orderBO);
            map.put("valid", !result);
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
        }
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "application/json; charset=utf-8");
        return new ResponseEntity<String>(MineJacksonkMapper.convertObjectToString(map), responseHeaders,
            HttpStatus.OK);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 分页查询普通用户的其他订单信息
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年1月3日]
     * @param request
     * @param orderBO
     * @return
     * @throws MineException
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/queryOrder")
    public ResponseEntity<String> queryOrder(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
        throws MineException
    {
        String retCode = null;
        MinePagination<OrderVO> result = null;
        try
        {
            logger.info(orderBO.toString());
            
            // 验证innerID
            if (StringUtils.isBlank(orderBO.getInnerID()))
            {
                throw new MineException(SysCodeEnum.ERROR_INNERID_BLANK);
            }
            
            result = iOrderService.queryOrderList(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, result);
    }
    
    @RequestMapping(value = "/queryQtOrder")
    public ResponseEntity<String> queryQtOrder(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
        throws MineException
    {
        String retCode = null;
        MinePagination<OrderVO> result = null;
        try
        {
            logger.info(orderBO.toString());
            
            // 验证innerID
            if (StringUtils.isBlank(orderBO.getInnerID()))
            {
                throw new MineException(SysCodeEnum.ERROR_INNERID_BLANK);
            }
            
            result = iOrderService.queryQtOrderList(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, result);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 查询所有的订单信息
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年1月3日]
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/queryAllOrder")
    public ResponseEntity<String> queryAllOrder(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        MinePagination<OrderVO> list = null;
        try
        {
            logger.info(orderBO.toString());
            
            list = iOrderService.queryOrderListTo(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    @RequestMapping(value = "/queryChildRebateList")
    public ResponseEntity<String> queryChildRebateList(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        MinePagination<OrderVO> list = null;
        try
        {
            logger.info(orderBO.toString());
            
            list = iOrderService.queryChildRebateList(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 对比订单信息
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年1月9日]
     * @param request
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/compare")
    public ResponseEntity<String> compareOrder(HttpServletRequest request)
    {
        String retCode = null;
        List<OrderVO> list = null;
        try
        {
            logger.info("compareOrder control");
            
            // 汇率设置判断
            // if (OrderBO.CJ_RATE == 0 || OrderBO.CA_RATE == 0 )
            // {
            // throw new MineException(SysCodeEnum.ERROR_RATE_NOT_SET);
            // }
            
            // 返利率设置判断
            // if (OrderBO.CJ_REBATE_RATE == 0 || OrderBO.CA_REBATE_RATE == 0 )
            // {
            // throw new MineException(SysCodeEnum.ERROR_RABATE_RATE_NOT_SET);
            // }
            
            list = iOrderService.compareOrderCorrect();
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    @RequestMapping(value = "/compareCnamz")
    public ResponseEntity<String> compareCnamzOrder(HttpServletRequest request)
    {
        String retCode = null;
        List<OrderVO> list = null;
        try
        {
            logger.info("compareCnamzOrder control");
            
            list = iOrderService.compareCnamzOrderCorrect();
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    @RequestMapping(value = "/compareJpamz")
    public ResponseEntity<String> compareJpamzOrder(HttpServletRequest request)
    {
        String retCode = null;
        List<RyReportVO> list = null;
        try
        {
            logger.info("compareJpamzOrder control");
            
            list = iOrderService.compareJpamzOrderCorrect();
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 设置人民币对日元汇率
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年1月9日]
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/paramsSet")
    public ResponseEntity<String> paramsSet(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        try
        {
            logger.info(orderBO.toString());
            
            if (ShopSiteEnum.NEW_AMAZON_JP.getSite().equals(orderBO.getShopSite()))
            {
                OrderBO.CJ_RATE = orderBO.getRate();
                OrderBO.CJ_REBATE_RATE = orderBO.getRebateRate();
                OrderBO.CJ_CONVERT_RATE = orderBO.getConvertRate();
            }
            else if (ShopSiteEnum.LPM_COM.getSite().equals(orderBO.getShopSite()))
            {
                OrderBO.CA_RATE = orderBO.getRate();
                OrderBO.CA_REBATE_RATE = orderBO.getRebateRate();
            }
            else if (ShopSiteEnum.JPLT_COM.getSite().equals(orderBO.getShopSite()))
            {
                OrderBO.CJ_RATE = orderBO.getRate();
                OrderBO.CLT_REBATE_RATE = orderBO.getRebateRate();
            }
            else if (ShopSiteEnum.LTGJ_COM.getSite().equals(orderBO.getShopSite()))
            {
                OrderBO.CA_RATE = orderBO.getRate();
                OrderBO.CLTGJ_REBATE_RATE = orderBO.getRebateRate();
            }
            else if (ShopSiteEnum.AMAZON_CN.getSite().equals(orderBO.getShopSite()))
            {
                // OrderBO.CN_RATE = orderBO.getRate();
                OrderBO.CN_REBATE_RATE = orderBO.getRebateRate();
            }
            OrderBO.PARENT_REBATE_MONTH = orderBO.getParentRebateMonth();
            OrderBO.PARENT_REBATE_RATE = orderBO.getParentRebateRate();
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 获取人民币对日元汇率
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年1月9日]
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/paramsGet")
    public ResponseEntity<String> paramsGet(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        OrderBO order = new OrderBO();
        try
        {
            logger.info("rateGet");
            
            if (StringUtils.isNotBlank(orderBO.getShopSite()))
            {
                if (ShopSiteEnum.NEW_AMAZON_JP.getSite().equals(orderBO.getShopSite()))
                {
                    order.setRate(OrderBO.CJ_RATE);
                    order.setRebateRate(OrderBO.CJ_REBATE_RATE);
                    order.setConvertRate(OrderBO.CJ_CONVERT_RATE);
                }
                else if (ShopSiteEnum.LPM_COM.getSite().equals(orderBO.getShopSite()))
                {
                    order.setRate(OrderBO.CA_RATE);
                    order.setRebateRate(OrderBO.CA_REBATE_RATE);
                }
                else if (ShopSiteEnum.JPLT_COM.getSite().equals(orderBO.getShopSite()))
                {
                    order.setRate(OrderBO.CJ_RATE);
                    order.setRebateRate(OrderBO.CLT_REBATE_RATE);
                }
                else if (ShopSiteEnum.LTGJ_COM.getSite().equals(orderBO.getShopSite()))
                {
                    order.setRate(OrderBO.CA_RATE);
                    order.setRebateRate(OrderBO.CLTGJ_REBATE_RATE);
                }
                else if (ShopSiteEnum.AMAZON_CN.getSite().equals(orderBO.getShopSite()))
                {
                    // order.setRate(OrderBO.CN_RATE);
                    order.setRebateRate(OrderBO.CN_REBATE_RATE);
                }
            }
            else
            {
                order.setRate(OrderBO.CJ_RATE);
                order.setRebateRate(OrderBO.CJ_REBATE_RATE);
            }
            order.setParentRebateMonth(OrderBO.PARENT_REBATE_MONTH);
            order.setParentRebateRate(OrderBO.PARENT_REBATE_RATE);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, order);
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 求和查询订单信息
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年1月9日]
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/querySum")
    public ResponseEntity<String> querySum(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        OrderVO orderVO = null;
        try
        {
            logger.info(orderBO.toString());
            
            orderVO = iOrderService.querySum(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, orderVO);
    }
    
    @RequestMapping(value = "/queryQtSum")
    public ResponseEntity<String> queryQtSum(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        OrderVO orderVO = null;
        try
        {
            logger.info(orderBO.toString());
            
            orderVO = iOrderService.queryQtSum(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, orderVO);
    }
    
    @RequestMapping(value = "/queryAllSum")
    public ResponseEntity<String> queryAllSum(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        OrderVO orderVO = null;
        try
        {
            logger.info(orderBO.toString());
            
            orderVO = iOrderService.queryAllSum(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, orderVO);
    }
    
    @RequestMapping(value = "/queryAllSumChildRebate")
    public ResponseEntity<String> queryAllSumChildRebate(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        OrderVO orderVO = null;
        try
        {
            logger.info(orderBO.toString());
            
            orderVO = iOrderService.queryAllSumChildRebate(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, orderVO);
    }
    
    /**
     * <一句话功能简述></br>
     * 
     * 查看我的佣金
     *
     * <功能详细描述></br>
     * 
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/queryRebate")
    public ResponseEntity<String> queryRebate(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        MinePagination<Map<String, String>> list = null;
        try
        {
            logger.info(orderBO.toString());
            
            list = iOrderService.queryRebate(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    /**
     * <一句话功能简述></br>
     * 
     * 查看我的线下贡献
     *
     * <功能详细描述></br>
     * 
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/queryChildRebate")
    public ResponseEntity<String> queryChildRebate(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        MinePagination<Map<String, String>> list = null;
        try
        {
            logger.info(orderBO.toString());
            
            list = iOrderService.queryChildRebate(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    /**
     * <一句话功能简述></br>
     * 
     * 查询所有用户的佣金信息
     *
     * <功能详细描述></br>
     * 
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/queryAllRebate")
    public ResponseEntity<String> queryAllRebate(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        MinePagination<Map<String, String>> list = null;
        try
        {
            logger.info(orderBO.toString());
            
            list = iOrderService.queryAllRebate(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    /**
     * <一句话功能简述></br>
     * 
     * 查询所有用户的所有下线用户的返利贡献金额
     *
     * <功能详细描述></br>
     * 
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/queryAllChildRebate")
    public ResponseEntity<String> queryAllChildRebate(HttpServletRequest request, @ModelAttribute OrderBO orderBO)
    {
        String retCode = null;
        MinePagination<Map<String, String>> list = null;
        try
        {
            logger.info(orderBO.toString());
            
            list = iOrderService.queryAllChildRebate(orderBO);
            retCode = MineErrorCode.SUCCESS.name();
        }
        catch (MineException e)
        {
            logger.error(e.getErrorCode().name(), e);
            retCode = e.getErrorCode().name();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        return getResponseEntity(retCode, list);
    }
    
    /**
     * <一句话功能简述></br>
     * 
     * 普通用户导出订单信息
     *
     * <功能详细描述></br>
     * 
     * @param request
     * @param response
     * @param orderBO
     * @throws MineException
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/exportOrderData")
    public void exportOrderData(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute OrderBO orderBO)
        throws MineException
    {
        try
        {
            logger.info(orderBO.toString());
            
            MineExcelReport excelReport = iOrderService.exportOrderData(orderBO);
            // 清除首部空白行
            response.reset();
            // 设置以流方式写出
            response.setContentType("application/vnd.ms-excel; charset=utf-8");
            // 设置为"ISO-8859-1"可适配FIREFOX文件名中文，IE乱码，设置为UTF8，IE中文，FIREFOX乱码。。。
            response.setHeader("Content-Disposition",
                "attachment; filename=" + new String((new Date().getTime() + ".xls").getBytes(), "ISO-8859-1"));
            
            OutputStream ouputStream = response.getOutputStream();
            // 写出到响应流
            excelReport.write(ouputStream);
            // 关闭读写
            excelReport.dispose();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
        }
    }
    
    @RequestMapping(value = "/exportQtOrderData")
    public void exportQtOrderData(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute OrderBO orderBO)
        throws MineException
    {
        try
        {
            logger.info(orderBO.toString());
            
            MineExcelReport excelReport = iOrderService.exportQtOrderData(orderBO);
            // 清除首部空白行
            response.reset();
            // 设置以流方式写出
            response.setContentType("application/vnd.ms-excel; charset=utf-8");
            // 设置为"ISO-8859-1"可适配FIREFOX文件名中文，IE乱码，设置为UTF8，IE中文，FIREFOX乱码。。。
            response.setHeader("Content-Disposition",
                "attachment; filename=" + new String((new Date().getTime() + ".xls").getBytes(), "ISO-8859-1"));
            
            OutputStream ouputStream = response.getOutputStream();
            // 写出到响应流
            excelReport.write(ouputStream);
            // 关闭读写
            excelReport.dispose();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
        }
    }
    
    /**
     * <一句话功能简述></br>
     * 
     * 管理员用户导出订单execl
     *
     * <功能详细描述></br>
     * 
     * @param request
     * @param response
     * @param orderBO
     * @throws MineException
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/exportAllOrderData")
    public void exportAllOrderData(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute OrderBO orderBO)
        throws MineException
    {
        try
        {
            logger.info(orderBO.toString());
            
            MineExcelReport excelReport = iOrderService.exportAllOrderData(orderBO);
            // 清除首部空白行
            response.reset();
            // 设置以流方式写出
            response.setContentType("application/vnd.ms-excel; charset=utf-8");
            // 设置为"ISO-8859-1"可适配FIREFOX文件名中文，IE乱码，设置为UTF8，IE中文，FIREFOX乱码。。。
            response.setHeader("Content-Disposition",
                "attachment; filename=" + new String((new Date().getTime() + ".xls").getBytes(), "ISO-8859-1"));
            
            OutputStream ouputStream = response.getOutputStream();
            // 写出到响应流
            excelReport.write(ouputStream);
            // 关闭读写
            excelReport.dispose();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
        }
    }
    
    /**
     * <pre>
     * <一句话功能简述>
     * 
     * 导出用户的返利数据
     * 
     * <功能详细描述>
     * </pre>
     *
     * @author xuganhua
     * @version [版本号, 2016年2月17日]
     * @param request
     * @param orderBO
     * @return
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/exportAllRebateData")
    public void exportAllRebateData(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute OrderBO orderBO)
    {
        try
        {
            logger.info(orderBO.toString());
            
            MineExcelReport excelReport = iOrderService.exportAllRebateData(orderBO);
            // 清除首部空白行
            response.reset();
            // 设置以流方式写出
            response.setContentType("application/vnd.ms-excel; charset=utf-8");
            // 设置为"ISO-8859-1"可适配FIREFOX文件名中文，IE乱码，设置为UTF8，IE中文，FIREFOX乱码。。。
            response.setHeader("Content-Disposition",
                "attachment; filename=" + new String((new Date().getTime() + ".xls").getBytes(), "ISO-8859-1"));
            
            OutputStream ouputStream = response.getOutputStream();
            // 写出到响应流
            excelReport.write(ouputStream);
            // 关闭读写
            excelReport.dispose();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
        }
    }
    
    /**
     * <一句话功能简述></br>
     * 
     * 导出用户的返利贡献数据
     *
     * <功能详细描述></br>
     * 
     * @param request
     * @param response
     * @param orderBO
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/exportAllChildRebateData")
    public void exportAllChildRebateData(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute OrderBO orderBO)
    {
        try
        {
            logger.info(orderBO.toString());
            
            MineExcelReport excelReport = iOrderService.exportAllChildRebateData(orderBO);
            // 清除首部空白行
            response.reset();
            // 设置以流方式写出
            response.setContentType("application/vnd.ms-excel; charset=utf-8");
            // 设置为"ISO-8859-1"可适配FIREFOX文件名中文，IE乱码，设置为UTF8，IE中文，FIREFOX乱码。。。
            response.setHeader("Content-Disposition",
                "attachment; filename=" + new String((new Date().getTime() + ".xls").getBytes(), "ISO-8859-1"));
            
            OutputStream ouputStream = response.getOutputStream();
            // 写出到响应流
            excelReport.write(ouputStream);
            // 关闭读写
            excelReport.dispose();
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
        }
    }
    
    @RequestMapping(value = "/deleteOrder")
    public ResponseEntity<String> deleteOrder(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute OrderBO orderBO)
    {
        String retCode = MineErrorCode.SUCCESS.name();
        try
        {
            logger.info(orderBO.toString());
            
            iOrderService.deleteOrder(orderBO);
        }
        catch (Exception e)
        {
            logger.error(e.getMessage(), e);
            retCode = MineErrorCode.ERROR_INTERNAL.name();
        }
        
        return getResponseEntity(retCode);
    }
    
}
